home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / app / gimphelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-01-14  |  6.8 KB  |  292 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * gimphelp.c
  5.  * Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  */
  21. #include "config.h"
  22.  
  23. #ifdef HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #ifdef HAVE_STRING_H
  27. #include <string.h>
  28. #endif
  29.  
  30. #include <gtk/gtk.h>
  31.  
  32. #include "gimphelp.h"
  33. #include "gimprc.h"
  34. #include "gimpui.h"
  35. #include "plug_in.h"
  36. #include "procedural_db.h"
  37.  
  38. #include "libgimp/gimpenv.h"
  39.  
  40. #include "libgimp/gimpintl.h"
  41.  
  42. /*
  43. #ifndef G_OS_WIN32
  44. #define DEBUG_HELP
  45. #endif
  46. */
  47.  
  48. typedef struct _GimpIdleHelp GimpIdleHelp;
  49.  
  50. struct _GimpIdleHelp
  51. {
  52.   gchar *help_path;
  53.   gchar *help_data;
  54. };
  55.  
  56. /*  local function prototypes  */
  57. static gint      gimp_idle_help     (gpointer     data);
  58. static gboolean  gimp_help_internal (const gchar *help_path,
  59.                      const gchar *current_locale,
  60.                      const gchar *help_data);
  61. static void      gimp_help_netscape (const gchar *help_path,
  62.                      const gchar *current_locale,
  63.                      const gchar *help_data);
  64.  
  65. /**********************/
  66. /*  public functions  */
  67. /**********************/
  68.  
  69. /*  The standard help function  */
  70. void
  71. gimp_standard_help_func (const gchar *help_data)
  72. {
  73.   gimp_help (NULL, help_data);
  74. }
  75.  
  76. /*  the main help function  */
  77. void
  78. gimp_help (const gchar *help_path,
  79.        const gchar *help_data)
  80. {
  81.   if (use_help)
  82.     {
  83.       GimpIdleHelp *idle_help;
  84.  
  85.       idle_help = g_new0 (GimpIdleHelp, 1);
  86.  
  87.       if (help_path && strlen (help_path))
  88.     idle_help->help_path = g_strdup (help_path);
  89.  
  90.       if (help_data && strlen (help_data))
  91.     idle_help->help_data = g_strdup (help_data);
  92.  
  93.       gtk_idle_add ((GtkFunction) gimp_idle_help, (gpointer) idle_help);
  94.     }
  95. }
  96.  
  97. /*********************/
  98. /*  local functions  */
  99. /*********************/
  100.  
  101. static gint
  102. gimp_idle_help (gpointer data)
  103. {
  104.   GimpIdleHelp *idle_help;
  105.   static gchar *current_locale = "C";
  106.  
  107.   idle_help = (GimpIdleHelp *) data;
  108.  
  109.   if (idle_help->help_data == NULL && help_browser != HELP_BROWSER_GIMP)
  110.     idle_help->help_data = g_strdup ("introduction.html");
  111.  
  112. #ifdef DEBUG_HELP
  113.   if (idle_help->help_path)
  114.     g_print ("Help Path: %s\n", idle_help->help_path);
  115.   else
  116.     g_print ("Help Path: NULL\n");
  117.  
  118.   if (idle_help->help_data)
  119.     g_print ("Help Page: %s\n", idle_help->help_data);
  120.   else
  121.     g_print ("Help Page: NULL\n");
  122.  
  123.   g_print ("\n");
  124. #endif  /*  DEBUG_HELP  */
  125.  
  126.   switch (help_browser)
  127.     {
  128.     case HELP_BROWSER_GIMP:
  129.       if (gimp_help_internal (idle_help->help_path,
  130.                   current_locale,
  131.                   idle_help->help_data))
  132.     break;
  133.       if (idle_help->help_data == NULL)
  134.     idle_help->help_data = g_strdup ("introduction.html");
  135.  
  136.       /* Fallthrough */
  137.  
  138.     case HELP_BROWSER_NETSCAPE:
  139.       gimp_help_netscape (idle_help->help_path,
  140.               current_locale,
  141.               idle_help->help_data);
  142.       break;
  143.  
  144.     default:
  145.       break;
  146.     }
  147.  
  148.   if (idle_help->help_path)
  149.     g_free (idle_help->help_path);
  150.   if (idle_help->help_data)
  151.     g_free (idle_help->help_data);
  152.   g_free (idle_help);
  153.  
  154.   return FALSE;
  155. }
  156.  
  157. static void
  158. gimp_help_internal_not_found_callback (GtkWidget *widget,
  159.                        gboolean   use_netscape,
  160.                        gpointer   data)
  161. {
  162.   GList *update = NULL;
  163.   GList *remove = NULL;
  164.  
  165.   if (use_netscape)
  166.     {
  167.       help_browser = HELP_BROWSER_NETSCAPE;
  168.  
  169.       update = g_list_append (update, "help-browser");
  170.       save_gimprc (&update, &remove);
  171.     }
  172.   
  173.   gtk_main_quit ();
  174. }
  175.  
  176. static gboolean
  177. gimp_help_internal (const gchar *help_path,
  178.             const gchar *current_locale,
  179.             const gchar *help_data)
  180. {
  181.   ProcRecord *proc_rec;
  182.  
  183.   /*  Check if a help browser is already running  */
  184.   proc_rec = procedural_db_lookup ("extension_gimp_help_browser_temp");
  185.  
  186.   if (proc_rec == NULL)
  187.     {
  188.       Argument *args = NULL;
  189.  
  190.       proc_rec = procedural_db_lookup ("extension_gimp_help_browser");
  191.  
  192.       if (proc_rec == NULL)
  193.     {
  194.       GtkWidget *not_found =
  195.         gimp_query_boolean_box (_("Could not find GIMP Help Browser"),
  196.                     NULL, NULL, FALSE,
  197.                     _("Could not find the GIMP Help Browser procedure.\n"
  198.                       "It probably was not compiled because\n"
  199.                       "you don't have GtkXmHTML installed."),
  200.                     _("Use Netscape instead"),
  201.                     _("Cancel"), 
  202.                     NULL, NULL,
  203.                     gimp_help_internal_not_found_callback,
  204.                     NULL);
  205.       gtk_widget_show (not_found);
  206.       gtk_main ();
  207.       
  208.       return (help_browser != HELP_BROWSER_NETSCAPE);
  209.     }
  210.  
  211.       args = g_new (Argument, 4);
  212.       args[0].arg_type = PDB_INT32;
  213.       args[0].value.pdb_int = RUN_INTERACTIVE;
  214.       args[1].arg_type = PDB_STRING;
  215.       args[1].value.pdb_pointer = (gpointer) help_path;
  216.       args[2].arg_type = PDB_STRING;
  217.       args[2].value.pdb_pointer = (gpointer) current_locale;
  218.       args[3].arg_type = PDB_STRING;
  219.       args[3].value.pdb_pointer = (gpointer) help_data;
  220.  
  221.       plug_in_run (proc_rec, args, 4, FALSE, TRUE, 0);
  222.  
  223.       g_free (args);
  224.     }
  225.   else
  226.     {
  227.       Argument *return_vals;
  228.       gint      nreturn_vals;
  229.  
  230.       return_vals =
  231.         procedural_db_run_proc ("extension_gimp_help_browser_temp",
  232.                                 &nreturn_vals,
  233.                 PDB_STRING, help_path,
  234.                 PDB_STRING, current_locale,
  235.                                 PDB_STRING, help_data,
  236.                                 PDB_END);
  237.  
  238.       procedural_db_destroy_args (return_vals, nreturn_vals);
  239.     }
  240.  
  241.   return TRUE;
  242. }
  243.  
  244. static void
  245. gimp_help_netscape (const gchar *help_path,
  246.             const gchar *current_locale,
  247.             const gchar *help_data)
  248. {
  249.   Argument *return_vals;
  250.   gint      nreturn_vals;
  251.   gchar    *url;
  252.  
  253.   if (help_data && help_data[0] == '/')    /* _not_ g_path_is_absolute() */
  254.     {
  255.       url = g_strconcat ("file:",
  256.              help_data,
  257.              NULL);
  258.     }
  259.   else
  260.     {
  261.       if (!help_path)
  262.     {
  263.       url = g_strconcat ("file:",
  264.                  gimp_data_directory (),
  265.                  "/help/",
  266.                  current_locale, "/",
  267.                  help_data,
  268.                  NULL);
  269.     }
  270.       else
  271.     {
  272.       url = g_strconcat ("file:",
  273.                  help_path, "/",
  274.                  current_locale, "/",
  275.                  help_data,
  276.                  NULL);
  277.     }
  278.     }
  279.  
  280.   return_vals =
  281.     procedural_db_run_proc ("extension_web_browser",
  282.                 &nreturn_vals,
  283.                 PDB_INT32,  RUN_NONINTERACTIVE,
  284.                 PDB_STRING, url,
  285.                 PDB_INT32,  FALSE,
  286.                 PDB_END);
  287.  
  288.   procedural_db_destroy_args (return_vals, nreturn_vals);
  289.  
  290.   g_free (url);
  291. }
  292.